package com.gis507.test.AISTest4;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;

/**
 * 1、继承Reducer
 * 2、设置输入输出类型
 * 3、重写reduce方法
 */
public class AISDataReducer extends Reducer<Text,AISDataBean, Text, AISDataBean> {

    //设置速度最大最小值
    private static final double MAXSPEED = 30;
    private static final double MINSPEED = 1;

    @Override
    protected void reduce(Text key, Iterable<AISDataBean> values, Context context) throws IOException, InterruptedException {

//        ArrayList<AISDataBean> aisList = new ArrayList<>();
        //1、遍历values
        for (AISDataBean value : values) {

            //判断速度是否超限
            if (value.getSpeed() > MINSPEED && value.getSpeed() < MAXSPEED){

                //写出
                context.write(key,value);

            }
        }
    }
}
